<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品类型" prop="type">
        <el-input
          v-model="queryParams.type"
          placeholder="请输入商品类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入商品价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销量" prop="sales">
        <el-input
          v-model="queryParams.sales"
          placeholder="请输入销量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品库存" prop="kucun">
        <el-input
          v-model="queryParams.kucun"
          placeholder="请输入商品库存"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品权重" prop="quanzhong">
        <el-input
          v-model="queryParams.quanzhong"
          placeholder="请输入商品权重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品分类" prop="fenlei">
        <el-input
          v-model="queryParams.fenlei"
          placeholder="请输入商品分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市场价格" prop="marketPrice">
        <el-input
          v-model="queryParams.marketPrice"
          placeholder="请输入市场价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成本" prop="costPrice">
        <el-input
          v-model="queryParams.costPrice"
          placeholder="请输入成本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收藏" prop="love">
        <el-input
          v-model="queryParams.love"
          placeholder="请输入收藏"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="虚拟销量" prop="virtualSales">
        <el-input
          v-model="queryParams.virtualSales"
          placeholder="请输入虚拟销量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

        <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="addPush(1)"
          v-hasPermi="['proSystem:proSystem:add']"
        >新增</el-button>
        </el-col>



      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['proSystem:proSystem:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['proSystem:proSystem:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['proSystem:proSystem:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <template>
      <el-table :data="proSystemList" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="商品分类">
                <span>{{ props.row.fenlei }}</span>
              </el-form-item>
              <el-form-item label="商品市场价格">
                <span>{{ props.row.marketPrice }}</span>
              </el-form-item>
              <el-form-item label="成本价格">
                <span>{{ props.row.costPrice }}</span>
              </el-form-item>

              <el-form-item label="收藏">
                <span>{{ props.row.love }}</span>
              </el-form-item>
              <el-form-item label="虚拟销量">
                <span>{{ props.row.virtualSales }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="商品id" align="center" prop="id" />
        <el-table-column label="商品类型" align="center" prop="type" />
        <el-table-column label="商品图" align="center" prop="img" width="100">
          <template slot-scope="scope">
            <image-preview :src="scope.row.img" :width="50" :height="50"/>
          </template>
        </el-table-column>
        <el-table-column label="商品名称" align="center" prop="name" />
        <el-table-column label="商品价格" align="center" prop="price" />
        <el-table-column label="销量" align="center" prop="sales" />
        <el-table-column label="商品库存" align="center" prop="kucun" />
        <el-table-column label="商品权重" align="center" prop="quanzhong" />
        <el-table-column label="商品状态" align="center" prop="status" />

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['proSystem:proSystem:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['proSystem:proSystem:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>



    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />






  </div>
</template>

<script>
import { listProSystem, getProSystem, delProSystem, addProSystem, updateProSystem } from "@/api/product/pro";

export default {
  name: "ProSystem",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户首页展示表格数据
      proSystemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        img: null,
        type: null,
        name: null,
        price: null,
        sales: null,
        kucun: null,
        quanzhong: null,
        status: null,
        fenlei: null,
        marketPrice: null,
        costPrice: null,
        love: null,
        virtualSales: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    addPush(tableId){
      this.$router.push({
        path:'/test/subtest',
        query:{
          form:tableId
        }
      })
    },
    /** 查询用户首页展示列表 */
    getList() {
      this.loading = true;
      listProSystem(this.queryParams).then(response => {
        this.proSystemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        img: null,
        type: null,
        name: null,
        price: null,
        sales: null,
        kucun: null,
        quanzhong: null,
        status: null,
        fenlei: null,
        marketPrice: null,
        costPrice: null,
        love: null,
        virtualSales: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户首页展示";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProSystem(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户首页展示";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProSystem(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProSystem(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户首页展示编号为"' + ids + '"的数据项？').then(function () {
        return delProSystem(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('proSystem/proSystem/export', {
        ...this.queryParams
      }, `proSystem_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
